home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 1 / Amiga Tools.iso / egs-tools / egs_demo-version / egs_devels / examples / beginner_gadgets / gadget6.c < prev    next >
C/C++ Source or Header  |  1994-06-06  |  6KB  |  184 lines

  1. /**************************************************************************
  2. *****                       Gadget Demo 6                             *****
  3. *****                                                                 *****
  4. *****                     by John J. Karcher                          *****
  5. *****                                                                 *****
  6. *****                       10 August 1992                            *****
  7. *****                       10 Jan 1993 mvk                           *****
  8. *****                                                                 *****
  9. **************************************************************************/
  10.  
  11. /*
  12.    This program is exactly the same as the previous one, except that
  13.    the rows and columns are spaced and sized equally.
  14.  
  15.    This demonstrates how to use CreateVertiTable() to get gadgets
  16.    arranged more neatly.
  17. */
  18.  
  19. #include <stdio.h>
  20. #include <exec/types.h>
  21. #include <egs/egsintui.h>
  22. #include <egs/egsgadbox.h>
  23. #include <proto/exec.h>
  24. #include <egs/proto/all.h>
  25.  
  26.  
  27. #define  GAD_1_ID    1
  28. #define  GAD_2_ID    2
  29. #define  GAD_3_ID    3
  30.  
  31. BYTE  CreateGfx(void);
  32. BYTE  CreateWindow(void);
  33.  
  34.  
  35. struct Library *EGSIntuiBase;
  36. struct Library *EGBBase;
  37.  
  38. struct EB_GadContextNode   *GadCon;
  39. struct EI_Window           *Win;
  40.  
  41.  
  42. BYTE  CreateGfx(void)
  43. {
  44.    struct EB_GadBox           *root, *b1, *b2, *b3;
  45.    BYTE  ret = 0;
  46.  
  47.    if (GadCon = EB_CreateGadContext(NULL, NULL, -1, -1))
  48.      {
  49.       root = EB_CreateVertiTable(GadCon);
  50.       EB_AddLastSon(root, EB_CreateVertiFill(GadCon, TRUE, 0));
  51.  
  52.       b1 = EB_CreateHorizBox(GadCon);
  53.       EB_AddLastSon(root, b1);
  54.       EB_AddLastSon(b1, EB_CreateHorizFill(GadCon, TRUE, 0));
  55.       EB_AddLastSon(b1, EB_CreateTextAction(GadCon, "_Leave Me Alone", GAD_2_ID, EB_FILL_ALL));
  56.       EB_AddLastSon(b1, EB_CreateHorizFill(GadCon, TRUE, 0));
  57.       EB_AddLastSon(b1, EB_CreateTextAction(GadCon, "_Help Me", GAD_3_ID, EB_FILL_ALL));
  58.       EB_AddLastSon(b1, EB_CreateHorizFill(GadCon, TRUE, 0));
  59.       EB_AddLastSon(b1, EB_CreateTextAction(GadCon, "_Push Me", GAD_1_ID, EB_FILL_ALL));
  60.       EB_AddLastSon(b1, EB_CreateHorizFill(GadCon, TRUE, 0));
  61.  
  62.       EB_AddLastSon(root, EB_CreateVertiFill(GadCon, TRUE, 0));
  63.  
  64.       b2 = EB_CreateHorizBox(GadCon);
  65.       EB_AddLastSon(root, b2);
  66.       EB_AddLastSon(b2, EB_CreateHorizFill(GadCon, TRUE, 0));
  67.       EB_AddLastSon(b2, EB_CreateTextAction(GadCon, "_Push Me", GAD_1_ID, EB_FILL_ALL));
  68.       EB_AddLastSon(b2, EB_CreateHorizFill(GadCon, TRUE, 0));
  69.       EB_AddLastSon(b2, EB_CreateTextAction(GadCon, "_Leave Me Alone", GAD_2_ID, EB_FILL_ALL));
  70.       EB_AddLastSon(b2, EB_CreateHorizFill(GadCon, TRUE, 0));
  71.       EB_AddLastSon(b2, EB_CreateTextAction(GadCon, "_Help Me", GAD_3_ID, EB_FILL_ALL));
  72.       EB_AddLastSon(b2, EB_CreateHorizFill(GadCon, TRUE, 0));
  73.  
  74.       EB_AddLastSon(root, EB_CreateVertiFill(GadCon, TRUE, 0));
  75.  
  76.       b3 = EB_CreateHorizBox(GadCon);
  77.       EB_AddLastSon(root, b3);
  78.       EB_AddLastSon(b3, EB_CreateHorizFill(GadCon, TRUE, 0));
  79.       EB_AddLastSon(b3, EB_CreateTextAction(GadCon, "_Help Me", GAD_3_ID, EB_FILL_ALL));
  80.       EB_AddLastSon(b3, EB_CreateHorizFill(GadCon, TRUE, 0));
  81.       EB_AddLastSon(b3, EB_CreateTextAction(GadCon, "_Push Me", GAD_1_ID, EB_FILL_ALL));
  82.       EB_AddLastSon(b3, EB_CreateHorizFill(GadCon, TRUE, 0));
  83.       EB_AddLastSon(b3, EB_CreateTextAction(GadCon, "_Leave Me Alone", GAD_2_ID, EB_FILL_ALL));
  84.       EB_AddLastSon(b3, EB_CreateHorizFill(GadCon, TRUE, 0));
  85.  
  86.       EB_AddLastSon(root, EB_CreateVertiFill(GadCon, TRUE, 0));
  87.  
  88.       root = EB_CreateMasterWindow(GadCon, Win, root);
  89.  
  90.       if (EB_ProcessGadBoxes(GadCon, root))
  91.         {
  92.          ret = 1;
  93.         }
  94.        }
  95.  
  96.    return ret;
  97. }
  98.  
  99. BYTE  CreateWindow(void)
  100. {
  101.    BYTE  ret = 0;
  102.  
  103.    if (CreateGfx())
  104.      {
  105.       GadCon->NewWin->Title              = "EGS Gadget Demo 6";
  106.       GadCon->NewWin->Flags             &= ~EI_SMART_REFRESH;
  107.       GadCon->NewWin->Flags             |= (EI_SIZEBBOTTOM | EI_WINDOWCENTER);
  108.       GadCon->NewWin->IDCMPFlags        |= (EI_iCLOSEWINDOW | EI_iGADGETUP | EI_iSIZEVERIFY | EI_iNEWSIZE);
  109.       GadCon->NewWin->Bordef.SysGadgets |= (EI_WINDOWCLOSE | EI_WINDOWSIZE);
  110.  
  111.       if (Win = EI_OpenWindow(GadCon->NewWin))
  112.         {
  113.          ret = 1;
  114.         }
  115.      }
  116.  
  117.    return ret;
  118. }
  119.  
  120. main()
  121. {
  122.    struct EI_EIntuiMsg  *IMsg;
  123.    struct EI_Gadget     *TempGad;
  124.    BYTE  quit = 0;
  125.  
  126.    if (EGSIntuiBase = OpenLibrary("egsintui.library", 0))
  127.      {
  128.       if (EGBBase = OpenLibrary("egsgadbox.library", 0))
  129.         {
  130.          if (CreateWindow())
  131.            {
  132.             while (!quit)
  133.               {
  134.                WaitPort(Win->UserPort);
  135.                if (IMsg = (struct EI_EIntuiMsg *)GetMsg(Win->UserPort))
  136.                  {
  137.                   if (IMsg->Class == EI_iCLOSEWINDOW)
  138.                     {
  139.                      quit = 1;
  140.                     }
  141.                   if (IMsg->Class == EI_iGADGETUP)
  142.                     {
  143.                      TempGad = (struct EI_Gadget *)IMsg->IAddress;
  144.                      if (TempGad->GadgetID == GAD_1_ID)
  145.                        {
  146.                         printf("You pressed me!\n");
  147.                        }
  148.                      if (TempGad->GadgetID == GAD_2_ID)
  149.                        {
  150.                         printf("You're not leaving me alone!\n");
  151.                        }
  152.                      if (TempGad->GadgetID == GAD_3_ID)
  153.                        {
  154.                         printf("You helped me!\n");
  155.                        }
  156.                     }
  157.                   if (IMsg->Class == EI_iSIZEVERIFY)
  158.                     {
  159.                      EI_RemoveGList(Win, GadCon->First, GadCon->Num);
  160.                      EB_DeleteGadContext(GadCon);
  161.                      GadCon = NULL;
  162.                     }
  163.                   if (IMsg->Class == EI_iNEWSIZE)
  164.                     {
  165.                      EI_LockIntuition();
  166.                      CreateGfx();
  167.                      if (GadCon)
  168.                        {
  169.                         EI_AddGList(Win, GadCon->First, GadCon->Num);
  170.                        }
  171.                      EI_UnlockIntuition();
  172.                     }
  173.                   ReplyMsg((struct Message *)IMsg);
  174.                  }
  175.               }
  176.            }
  177.          if (Win) EI_CloseWindow(Win);
  178.          if (GadCon) EB_DeleteGadContext(GadCon);
  179.          CloseLibrary(EGBBase);
  180.         }
  181.       CloseLibrary(EGSIntuiBase);
  182.      }
  183. }
  184.